import '@/assets/css/index.css'
import '@/assets/css/wangEditorHtmlDisplay.css' //通过wangEditor编辑出来的html是无样式的，要自己写（其实粘贴官方的就行）
// 引入highlight的css样式和vue插件
// 这里引入的是stackoverflow-light.css，可以去官网查看并替换成自己喜欢的css样式
import 'highlight.js/styles/stackoverflow-light.css'
import 'highlight.js/lib/common'
import hljsVuePlugin from '@highlightjs/vue-plugin'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'


import App from './App.vue'
import router from './router'
import '@fortawesome/fontawesome-free/css/all.css';


const app = createApp(App)

app.use(createPinia().use(piniaPluginPersistedstate))
app.use(ElementPlus,{locale: zhCn,})
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(router)
app.use(hljsVuePlugin)
app.mount('#app')


document.addEventListener('plusready', function() {
    var webview = plus.webview.currentWebview();
    plus.key.addEventListener('backbutton', function() {
        webview.canBack(function(e) {
            if (e.canBack) {
                webview.back(); // 返回上一页
            } else {
                var first = null;
                plus.key.addEventListener('backbutton', function() {
                    if (!first) {
                        first = new Date().getTime();
                        plus.nativeUI.toast('再按一次退出应用');
                        setTimeout(function() {
                            first = null;
                        }, 1000);
                    } else {
                        if (new Date().getTime() - first < 1500) {
                            plus.runtime.quit(); // 退出应用
                        }
                    }
                }, false);
            }
        });
    });
});

